home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / shfileop / shfileop.frm < prev    next >
Text File  |  1996-07-06  |  11KB  |  339 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   6735
  6.    ClientLeft      =   2565
  7.    ClientTop       =   1440
  8.    ClientWidth     =   7110
  9.    Height          =   7140
  10.    Left            =   2505
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   6735
  15.    ScaleWidth      =   7110
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   1095
  18.    Width           =   7230
  19.    Begin VB.CommandButton cmdExit 
  20.       Cancel          =   -1  'True
  21.       Caption         =   "E&xit"
  22.       Height          =   375
  23.       Left            =   3000
  24.       TabIndex        =   7
  25.       Top             =   4560
  26.       Width           =   1095
  27.    End
  28.    Begin VB.CommandButton cmdExecute 
  29.       Caption         =   "&Delete"
  30.       Height          =   375
  31.       Index           =   2
  32.       Left            =   3000
  33.       TabIndex        =   6
  34.       Top             =   3840
  35.       Width           =   1095
  36.    End
  37.    Begin VB.CommandButton cmdExecute 
  38.       Caption         =   "&Move >>"
  39.       Height          =   375
  40.       Index           =   1
  41.       Left            =   3000
  42.       TabIndex        =   5
  43.       Top             =   3360
  44.       Width           =   1095
  45.    End
  46.    Begin VB.CommandButton cmdExecute 
  47.       Caption         =   "&Copy >>"
  48.       Height          =   375
  49.       Index           =   0
  50.       Left            =   3000
  51.       TabIndex        =   4
  52.       Top             =   2880
  53.       Width           =   1095
  54.    End
  55.    Begin VB.FileListBox lstFile 
  56.       Height          =   2595
  57.       Index           =   1
  58.       Left            =   4200
  59.       TabIndex        =   11
  60.       Top             =   2640
  61.       Width           =   2775
  62.    End
  63.    Begin VB.DriveListBox cboDrive 
  64.       Height          =   315
  65.       Index           =   1
  66.       Left            =   4200
  67.       TabIndex        =   9
  68.       Top             =   360
  69.       Width           =   2775
  70.    End
  71.    Begin VB.DirListBox lstDir 
  72.       Height          =   1830
  73.       Index           =   0
  74.       Left            =   120
  75.       TabIndex        =   2
  76.       Top             =   720
  77.       Width           =   2775
  78.    End
  79.    Begin VB.DriveListBox cboDrive 
  80.       Height          =   315
  81.       Index           =   0
  82.       Left            =   120
  83.       TabIndex        =   1
  84.       Top             =   360
  85.       Width           =   2775
  86.    End
  87.    Begin VB.FileListBox lstFile 
  88.       Height          =   2595
  89.       Index           =   0
  90.       Left            =   120
  91.       MultiSelect     =   2  'Extended
  92.       TabIndex        =   3
  93.       Top             =   2640
  94.       Width           =   2775
  95.    End
  96.    Begin VB.Frame Frame2 
  97.       Caption         =   "Options"
  98.       Height          =   1335
  99.       Left            =   120
  100.       TabIndex        =   12
  101.       Top             =   5280
  102.       Width           =   6855
  103.       Begin VB.CheckBox chkShowFile 
  104.          Caption         =   "Show Name of Each File"
  105.          Height          =   255
  106.          Left            =   3360
  107.          TabIndex        =   19
  108.          Top             =   720
  109.          Value           =   1  'Checked
  110.          Width           =   2175
  111.       End
  112.       Begin VB.CheckBox chkConfirmMkDir 
  113.          Caption         =   "Confirm Create Directory"
  114.          Height          =   255
  115.          Left            =   3360
  116.          TabIndex        =   18
  117.          Top             =   480
  118.          Width           =   2415
  119.       End
  120.       Begin VB.CheckBox chkConfirmOp 
  121.          Caption         =   "Confirm Operations"
  122.          Height          =   255
  123.          Left            =   3360
  124.          TabIndex        =   17
  125.          Top             =   240
  126.          Value           =   1  'Checked
  127.          Width           =   2415
  128.       End
  129.       Begin VB.CheckBox chkRename 
  130.          Caption         =   "Rename on Collision"
  131.          Height          =   255
  132.          Left            =   240
  133.          TabIndex        =   16
  134.          Top             =   960
  135.          Width           =   2175
  136.       End
  137.       Begin VB.CheckBox chkShowDlg 
  138.          Caption         =   "Display Progress Dialog"
  139.          Height          =   255
  140.          Left            =   240
  141.          TabIndex        =   15
  142.          Top             =   720
  143.          Value           =   1  'Checked
  144.          Width           =   2175
  145.       End
  146.       Begin VB.CheckBox chkUndo 
  147.          Caption         =   "Allow Undo"
  148.          Height          =   255
  149.          Left            =   240
  150.          TabIndex        =   14
  151.          Top             =   480
  152.          Value           =   1  'Checked
  153.          Width           =   2175
  154.       End
  155.       Begin VB.CheckBox chkEntireDir 
  156.          Caption         =   "Include Entire Directory"
  157.          Height          =   255
  158.          Left            =   240
  159.          TabIndex        =   13
  160.          Top             =   240
  161.          Width           =   2175
  162.       End
  163.    End
  164.    Begin VB.DirListBox lstDir 
  165.       Height          =   1830
  166.       Index           =   1
  167.       Left            =   4200
  168.       TabIndex        =   10
  169.       Top             =   750
  170.       Width           =   2775
  171.    End
  172.    Begin VB.Label Label4 
  173.       Caption         =   "Destination:"
  174.       Height          =   255
  175.       Left            =   4200
  176.       TabIndex        =   8
  177.       Top             =   120
  178.       Width           =   2775
  179.    End
  180.    Begin VB.Label Label3 
  181.       Caption         =   "Source:"
  182.       Height          =   255
  183.       Left            =   120
  184.       TabIndex        =   0
  185.       Top             =   120
  186.       Width           =   2775
  187.    End
  188. End
  189. Attribute VB_Name = "Form1"
  190. Attribute VB_Creatable = False
  191. Attribute VB_Exposed = False
  192. 'This demo shows some of the features of the Windows 95 API
  193. 'Specifically, it uses the SHFileOperation function. This code
  194. 'accompanies the Programming Techniques column (October Visual
  195. 'Basic Programmer's Journal).
  196. '
  197. 'By Jonathan Wood, SoftCircuits 1996 (http://www.softcircuits.com)
  198. '
  199. 'Notes:
  200. '-As explained in the October column, Visual Basic 4 cannot take
  201. ' full advantage of SHFileOperation becuase of UDT-alignment
  202. ' issues. Specifically, the SHFILEOPSTRUCT UDT cannot be declared
  203. ' and constructed exactly as required by SHFileOperation and only
  204. ' the first 5 members are valid. For example, SHFileOperation
  205. ' shows the name of each file being processed unless you specify
  206. ' FOF_SIMPLEPROGRESS. If this flag is specified, the function
  207. ' takes a message in lpszProgressTitle. You cannot currently do
  208. ' this from Visual Basic.
  209.  
  210.  
  211. Option Explicit
  212.  
  213. 'SHFileOperation declarations
  214. Const FO_MOVE = 1
  215. Const FO_COPY = 2
  216. Const FO_DELETE = 3
  217. Const FO_RENAME = 4
  218.  
  219. Const FOF_MULTIDESTFILES = &H1      'Destination specifies multiple files
  220. Const FOF_SILENT = &H4              'Don't display progress dialog
  221. Const FOF_RENAMEONCOLLISION = &H8   'Rename if destination already exists
  222. Const FOF_NOCONFIRMATION = &H10     'Don't prompt user
  223. Const FOF_WANTMAPPINGHANDLE = &H20  'Fill in hNameMappings member
  224. Const FOF_ALLOWUNDO = &H40          'Store undo information if possible
  225. Const FOF_FILESONLY = &H80          'On *.*, don't copy directories
  226. Const FOF_SIMPLEPROGRESS = &H100    'Don't show name of each file
  227. Const FOF_NOCONFIRMMKDIR = &H200    'Don't confirm making any needed dirs
  228.  
  229. Private Type SHFILEOPSTRUCT
  230.     hwnd As Long
  231.     wFunc As Long
  232.     pFrom As String
  233.     pTo As String
  234.     fFlags As Integer
  235.     fAnyOperationsAborted As Boolean
  236.     hNameMappings As Long
  237.     lpszProgressTitle As String 'Used only if FOF_SIMPLEPROGRESS specified
  238. End Type
  239.  
  240. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  241.  
  242. Private Sub chkEntireDir_Click()
  243.     lstFile(0).Enabled = Not CBool(chkEntireDir)
  244. End Sub
  245.  
  246. 'Executes SHFileOperation with current options
  247. Private Sub cmdExecute_Click(Index As Integer)
  248.     Dim FileOp As SHFILEOPSTRUCT
  249.     
  250.     'Parent window of dialog box--just use 0
  251.     FileOp.hwnd = 0
  252.